﻿package view
{
    import com.core.*;
    import com.core.display.*;
    import com.greensock.*;
    import com.sh.game.global.*;
    import com.sh.game.util.*;
    import consts.*;
    import control.*;
    import flash.display.*;
    import flash.events.*;
    import flash.filters.*;
    import flash.geom.*;
    import flash.text.*;
    import flash.utils.*;
    import manager.*;
    import morn.core.components.*;

    public class NewGuideView extends Sprite
    {
        private var _field:TextField;
        private var cfgguide:Object;
        private var _bgSprite:Sprite;
        private var lv:int;
        public var gid:int;
        private var _container:Sprite;
        private var _guideMc:Clip;
        private var isload:Boolean = false;
        private var _dir:int = 0;
        private var _item:Object;
        private var _tt:Number = 1;
        private var _tweenLite1:TweenMax;
        private var _tweenLite2:TweenMax;
        private var huajuxing:Shape;
        private var isTxt:Boolean;
        private var format2:TextFormat;
        private var _byteLoader:Loader;
        private var timeoutID3:uint = 0;
        private var p5:Point;
        private var p:Point;
        private var p1:Point;
        private var p2:Point;
        private var p3:Point;
        private var fTaskArr:Array;
        private var timeoutID:uint;
        private var guideFlag:Boolean;
        private var guideImg:Image;
        private var timeline:TweenMax;
        private var square:Shape;
        private static var instance:NewGuideView;

        public function NewGuideView()
        {
            this.format2 = new TextFormat("宋体", 12, null, true);
            this.p5 = new Point();
            this.p = new Point(0, 0);
            this.p1 = new Point(0, 0);
            this.p2 = new Point(0, 0);
            this.p3 = new Point(0, 0);
            this.fTaskArr = [];
            return;
        }// end function

        public function init() : void
        {
            this.mouseChildren = false;
            this.mouseEnabled = false;
            this._bgSprite = new Sprite();
            var _loc_1:* = new Image();
            _loc_1.url = "png.common.guidebg";
            this._bgSprite.addChild(_loc_1);
            this._field = new TextField();
            this._field.width = 140;
            this._field.height = 20;
            this._field.defaultTextFormat = this.format2;
            this._field.textColor = MColor.New16;
            this._field.x = 17;
            this._field.y = 17;
            this._field.text = "开始游戏";
            this._field.autoSize = TextFieldAutoSize.CENTER;
            this._bgSprite.addChild(this._field);
            this.huajuxing = new Shape();
            addChild(this.huajuxing);
            this._container = new Sprite();
            this.guideImg = new Image();
            this.guideImg.url = "png.common.guide";
            this.guideImg.y = -27;
            this._container.addChild(this.guideImg);
            this.isload = true;
            var _loc_2:* = Control.create(NewGuideControl, this);
            ModelProxy.addObserver("newguide", _loc_2);
            this.cfgguide = ConfigDictionary.data.newguide;
            GlobalLayer.instance.getLayer("guideCon").addChild(this);
            this.visible = false;
            return;
        }// end function

        private function loadArrow(event:Event) : void
        {
            this._container = new Sprite();
            addChild(this._container);
            this.isload = true;
            return;
        }// end function

        public function show(param1:String, param2:Point) : void
        {
            if (GuideView.getInstance().visible)
            {
                return;
            }
            this._field.text = param1;
            var _loc_3:int = 0;
            if (this._tweenLite1)
            {
                this._tweenLite1.kill();
            }
            if (this._tweenLite2)
            {
                this._tweenLite2.kill();
            }
            if (this.square && this.square.parent)
            {
                this.square.graphics.clear();
                this.square.filters = [];
                this.square.parent.removeChild(this.square);
            }
            this._bgSprite.x = 0;
            this._bgSprite.y = 0;
            this._container.x = 0;
            this._container.y = 0;
            this._bgSprite.visible = true;
            if (this._dir == 5)
            {
                _loc_3 = 90;
                this._container.rotation = _loc_3;
                this._bgSprite.x = -82;
                this._bgSprite.y = 25;
            }
            else if (this._dir == 6)
            {
                _loc_3 = -180;
                this._container.rotation = _loc_3;
                this._bgSprite.x = -161 - 54;
                this._bgSprite.y = -26;
                this._container.x = -27;
            }
            else if (this._dir == 7)
            {
                _loc_3 = -90;
                this._container.rotation = _loc_3;
                this._bgSprite.x = -82;
                this._bgSprite.y = -106;
                this._container.y = -27;
            }
            else if (this._dir == 8)
            {
                this._container.rotation = _loc_3;
                this._bgSprite.x = 24;
                this._bgSprite.y = -26;
            }
            addChild(this._bgSprite);
            addChild(this._container);
            this.guideFlag = true;
            this.guideFlash();
            this.playGuide1();
            if (this.timeoutID3)
            {
                clearInterval(this.timeoutID3);
                this.timeoutID3 = 0;
            }
            this.timeoutID3 = setInterval(this.onEnterFrame, 100);
            return;
        }// end function

        public function clickHandler() : void
        {
            if (this.visible)
            {
                this._item.dispatchEvent(new MouseEvent(MouseEvent.CLICK));
            }
            return;
        }// end function

        private function guideFlash() : void
        {
            var _loc_1:String = null;
            var _loc_2:TextField = null;
            var _loc_3:String = null;
            var _loc_4:Label = null;
            var _loc_5:int = 0;
            var _loc_6:int = 0;
            if (this._item is Label)
            {
                this.isTxt = true;
                this.square = new Shape();
                this.square.graphics.lineStyle(1, 16766720);
                this.square.filters = [new GlowFilter(16580393, 0.8, 6, 6, 2, BitmapFilterQuality.LOW)];
                _loc_1 = this._item.text;
                _loc_2 = new TextField();
                _loc_2.htmlText = _loc_1;
                _loc_3 = _loc_2.text;
                _loc_4 = new Label();
                _loc_5 = _loc_3.indexOf(" ");
                if (_loc_5 > 0)
                {
                    _loc_4.text = _loc_3.substring(0, _loc_5);
                }
                else
                {
                    _loc_4.text = _loc_3;
                }
                _loc_4.autoSize = "left";
                _loc_6 = _loc_4.width;
                this.square.graphics.drawRect(this._item.x, this._item.y, _loc_6, 16);
                this.square.graphics.endFill();
                this._item.parent.addChild(this.square);
            }
            else
            {
                this.isTxt = false;
            }
            return;
        }// end function

        private function playGuide1() : void
        {
            if (this.guideFlag)
            {
                if (this._dir == 5 || this._dir == 7)
                {
                    this._tweenLite1 = TweenMax.to(this._bgSprite, this._tt, {y:this._bgSprite.y + 34, repeat:int.MAX_VALUE, yoyo:true});
                    this._tweenLite2 = TweenMax.to(this._container, this._tt, {y:this._container.y + 34, repeat:int.MAX_VALUE, yoyo:true});
                }
                else
                {
                    this._tweenLite1 = TweenMax.to(this._bgSprite, this._tt, {x:this._bgSprite.x + 34, repeat:int.MAX_VALUE, yoyo:true});
                    this._tweenLite2 = TweenMax.to(this._container, this._tt, {x:this._container.x + 34, repeat:int.MAX_VALUE, yoyo:true});
                }
            }
            return;
        }// end function

        private function openComplete() : void
        {
            return;
        }// end function

        private function onEnterFrame() : void
        {
            this.p5 = this.getPoint();
            this.x = this.p5.x;
            this.y = this.p5.y;
            this.visible = true;
            return;
        }// end function

        public function hide() : void
        {
            ModelProxy.change("data", "newguideflag", false);
            if (this.timeoutID)
            {
                clearTimeout(this.timeoutID);
                this.timeoutID = 0;
            }
            if (this._item)
            {
                this._item.filters = [];
            }
            if (this.square && this.square.parent)
            {
                this.square.graphics.clear();
                this.square.filters = [];
                this.square.parent.removeChild(this.square);
            }
            if (this._tweenLite1)
            {
                this._tweenLite1.kill();
            }
            if (this._tweenLite2)
            {
                this._tweenLite2.kill();
            }
            if (this.timeline)
            {
                this.timeline.kill();
            }
            this.guideFlag = false;
            this.visible = false;
            if (this.timeoutID3)
            {
                clearInterval(this.timeoutID3);
                this.timeoutID3 = 0;
            }
            if (this._guideMc && this._guideMc.parent)
            {
                this._guideMc.parent.removeChild(this._guideMc);
                this._guideMc.dispose();
                this._guideMc = null;
            }
            if (this._bgSprite.parent)
            {
                this._bgSprite.parent.removeChild(this._bgSprite);
            }
            if (this._container.parent)
            {
                this._container.parent.removeChild(this._container);
            }
            return;
        }// end function

        public function doGuide(param1:int) : void
        {
            if (GuideView.getInstance().visible)
            {
                return;
            }
            if (this.isload == false)
            {
                return;
            }
            var _loc_2:* = UserData.getOnlineData("guide");
            var _loc_3:* = int(this.cfgguide[param1].repeat);
            if (param1 == GuideType.GUIDE1 || param1 == GuideType.GUIDE2 || param1 == GuideType.GUIDE_RW || _loc_3 == 1)
            {
            }
            else if (_loc_2 == null || int(_loc_2[param1]) == 1)
            {
                return;
            }
            if (param1 == GuideType.GUIDE_RW)
            {
                if (NewGuideView.getInstance().visible)
                {
                    return;
                }
            }
            this.gid = param1;
            if (this.gid == 0)
            {
                return;
            }
            this._item = ModelProxy.getValue("guideitem", "guideid" + this.gid) as Object;
            if (this._item == null)
            {
                return;
            }
            var _loc_4:* = this.cfgguide[this.gid];
            if (!this.cfgguide[this.gid])
            {
                return;
            }
            var _loc_5:* = _loc_4.desc;
            if (this.timeoutID)
            {
                clearTimeout(this.timeoutID);
                this.timeoutID = 0;
            }
            if (param1 == GuideType.GUIDE_RW)
            {
                ModelProxy.change("data", "newguideflag", true);
                ModelProxy.change("data", "isdomouse", false);
                this.timeoutID = setTimeout(this.clickHandler, 15000);
            }
            else
            {
                ModelProxy.change("data", "newguideflag", false);
            }
            this.visible = false;
            this._dir = _loc_4.dir;
            this.show(_loc_5, this.getPoint());
            this.addGuide(param1);
            return;
        }// end function

        private function getPoint() : Point
        {
            var _loc_2:String = null;
            if (this._item == null)
            {
                this.hide();
                return this.p3;
            }
            if (GuideView.getInstance().visible)
            {
                this.hide();
                return this.p3;
            }
            if (this.gid > 0)
            {
                _loc_2 = this.cfgguide[this.gid].plugin;
                if (_loc_2 != null && _loc_2 != "")
                {
                    if (PluginManager.instance.getPluginState(_loc_2) == "close")
                    {
                        this.hide();
                    }
                }
            }
            var _loc_1:* = ModelProxy.getValue("mainui", "shownewguide");
            if (_loc_1 == true)
            {
                this.hide();
                return this.p3;
            }
            if (!this._item.parent || this._item.visible == false || !this._item.parent.parent || !this._item.stage)
            {
                this.hide();
                return this.p3;
            }
            if (this._dir == 5)
            {
                this.p.x = int(this._item.width / 2);
                this.p.y = int(this._item.height - 8);
            }
            else if (this._dir == 6)
            {
                this.p.x = -37;
                this.p.y = int(this._item.height / 2);
            }
            else if (this._dir == 7)
            {
                this.p.x = int(this._item.width / 2);
                this.p.y = 0;
            }
            else if (this._dir == 8)
            {
                this.p.x = this._item.width;
                this.p.y = int(this._item.height / 2);
            }
            this.p1 = this._item.localToGlobal(this.p3);
            if (this.p1.x == 40 && this.p1.y == 20 || this.p1.x == 40 && this.p1.y == 17 || this.p1.x == 160 && this.p1.y == 11)
            {
                this.hide();
                return this.p3;
            }
            this.p2.x = this.p1.x + this.p.x;
            this.p2.y = this.p1.y + this.p.y;
            return this.p2;
        }// end function

        public function showBtn(param1:int, param2:Object) : void
        {
            var _loc_3:* = new Point();
            if (param1 == 5)
            {
                _loc_3 = new Point(int(param2.width / 2), param2.height);
            }
            else if (param1 == 6)
            {
                _loc_3 = new Point(0, int(param2.height / 2));
            }
            else if (param1 == 7)
            {
                _loc_3 = new Point(int(param2.width / 2), 0);
            }
            else if (param1 == 8)
            {
                _loc_3 = new Point(param2.width, int(param2.height / 2));
            }
            var _loc_4:* = param2.localToGlobal(_loc_3);
            this.show("", _loc_4);
            return;
        }// end function

        public function doTaskGuide(param1:int, param2:int) : void
        {
            this.fTaskArr.push(param1);
            this.doGuide(param2);
            return;
        }// end function

        public function checkLvGuide(param1:int) : void
        {
            return;
        }// end function

        public function doGuide1(param1:int, param2:String) : void
        {
            var _loc_3:* = param1;
            x = int((GlobalLayer.instance.root.stageWidth - 700) / 2);
            ModelProxy.change("plugin", "open", {target:param2, point:new Point(GlobalLayer.instance.root.stageWidth / 2, GlobalLayer.instance.root.stageHeight / 2 - 120), top:new Point(x, 100)});
            return;
        }// end function

        public function addGuide(param1:int) : void
        {
            var _loc_2:* = UserData.getOnlineData("guide");
            if (_loc_2 == null)
            {
                return;
            }
            if (int(_loc_2[param1]) == 0)
            {
                ModelProxy.change("plugin", "sendSysMsg", {name:"activity", param:param1, cmd:1001});
                _loc_2[param1] = 1;
            }
            return;
        }// end function

        public function initGuideTask() : void
        {
            return;
        }// end function

        private function changeOpen(param1:int) : void
        {
            var _loc_2:* = UserData.getOnlineData("guide");
            var _loc_3:Boolean = false;
            if (_loc_2 && int(_loc_2[param1]) == 1)
            {
                _loc_3 = true;
            }
            if (_loc_3)
            {
                ModelProxy.change("guidegn", "" + param1, true);
            }
            else
            {
                ModelProxy.change("guidegn", "" + param1, false);
            }
            return;
        }// end function

        private function changeOpen1(param1:int, param2:int) : void
        {
            var _loc_3:* = this.cfgguide[param2].level;
            if (param1 >= _loc_3)
            {
                ModelProxy.change("guidegn", "" + param2, true);
            }
            else
            {
                ModelProxy.change("guidegn", "" + param2, false);
            }
            return;
        }// end function

        public function initGuide() : void
        {
            var _loc_1:* = UserData.getUserData("level");
            return;
        }// end function

        public function changeVisible(param1:int, param2:int) : void
        {
            var _loc_3:int = 0;
            var _loc_4:* = ModelProxy.getValue("guideitem", "guideid" + param2) as Object;
            var _loc_5:* = ModelProxy.getValue("guideitem", "guideid_" + param2) as Object;
            var _loc_6:* = ModelProxy.getValue("guideitem", "guideid_1" + param2) as Object;
            var _loc_7:* = UserData.getUserData("rein");
            if (!_loc_4)
            {
                return;
            }
            _loc_3 = this.cfgguide[param2].level;
            if (param1 < _loc_3 && _loc_7 == 0)
            {
                _loc_4.visible = false;
                if (_loc_5)
                {
                    _loc_5.visible = false;
                }
                if (_loc_6)
                {
                    _loc_6.visible = false;
                }
            }
            else
            {
                _loc_4.visible = true;
                if (_loc_5)
                {
                    _loc_5.visible = true;
                }
                if (_loc_6)
                {
                    _loc_6.visible = true;
                }
            }
            return;
        }// end function

        public function NeedLevel(param1:Object) : int
        {
            var _loc_2:int = 0;
            var _loc_3:* = ModelProxy.getValue("guideitem", "guideid" + param1) as Object;
            if (!_loc_3)
            {
                return 0;
            }
            var _loc_4:* = UserData.getUserData("level");
            _loc_2 = this.cfgguide[param1].level;
            if (_loc_4 >= _loc_2)
            {
                return 0;
            }
            return _loc_2;
        }// end function

        public function changeVisible1(param1:int) : void
        {
            var _loc_2:* = ModelProxy.getValue("guideitem", "guideid" + param1) as Object;
            var _loc_3:* = ModelProxy.getValue("guideitem", "guideid_" + param1) as Object;
            var _loc_4:* = ModelProxy.getValue("guideitem", "guideid_1" + param1) as Object;
            var _loc_5:* = this.cfgguide[param1].taskid;
            var _loc_6:Boolean = false;
            var _loc_7:* = UserData.getOnlineData("guide");
            if (UserData.getOnlineData("guide") != null && _loc_7[param1] == 1)
            {
                _loc_6 = true;
            }
            if (_loc_6 == false)
            {
                if (_loc_2)
                {
                    _loc_2.visible = false;
                }
                if (_loc_3)
                {
                    _loc_3.visible = false;
                }
                if (_loc_4)
                {
                    _loc_4.visible = false;
                }
            }
            else
            {
                if (_loc_2)
                {
                    _loc_2.visible = true;
                }
                if (_loc_3)
                {
                    _loc_3.visible = true;
                }
                if (_loc_4)
                {
                    _loc_4.visible = true;
                }
            }
            return;
        }// end function

        public static function getInstance() : NewGuideView
        {
            if (instance == null)
            {
                instance = new NewGuideView;
            }
            return instance;
        }// end function

    }
}
